package com.ll.menu.user.history.list;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.droid.library.widget.recyclerview.BaseRecyclerAdapter;
import com.droid.library.widget.recyclerview.BaseViewHolder;
import com.ll.menu.user.R;
import com.ll.menu.user.app.entity.Order;
import com.ll.menu.user.history.detail.HistoryDetailActivity;

/**
 * 订单历史列表
 *
 * @author wangheng
 */

public class HistoryListAdapter extends BaseRecyclerAdapter<Order> {
    public HistoryListAdapter(Activity activity) {
        super(activity);
    }

    @Override
    protected BaseViewHolder onCreateRealViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = mActivity.getLayoutInflater();
        View view = inflater.inflate(R.layout.item_history_list,parent,false);
        return new Holder(view,mActivity,HistoryListAdapter.this);
    }

    private class Holder extends BaseViewHolder<Order>{
        private TextView mTextView;
        public Holder(View itemView, Activity activity, BaseRecyclerAdapter<Order> adapter) {
            super(itemView, activity, adapter);

            mTextView = (TextView) itemView.findViewById(R.id.tvHistoryListItem);
        }

        @Override
        public void onBindViewHolder(int position, final Order item) {
            mTextView.setText(item.getDate());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    HistoryDetailActivity.launch(mActivity,item.getId(),item.getDate());
                }
            });
        }
    }
}
